1287A - Angry Students - CodeForces Solution


greedy implementation *800

Please click on ads to support us..

Python Code:

for i in range(int(input())):
    k = int(input())
    s = input().lstrip('P').split('A')
    print(len(max(s)))

C++ Code:

#include <iostream>
#include <algorithm>
#include <bitset>
#include <vector>
#include <deque>
#include <map>
#include <cmath>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <iomanip>
using namespace std;
#define int long long
#define gcd __gcd
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define hi cerr<<"HI"<<endl;
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#define yeah cout<<"YES\n";
#define nope cout<<"NO\n";

void solve(){
    int n; cin>>n;
    string s; cin>>s;
    int ans = 0;
    int cnt = 0;
    // int n = s.length();
    for(int i = n-1; i>=0; i--){
        if(s[i] == 'P'){cnt++;}
        if(s[i] == 'A'){ans = max(ans, cnt); cnt = 0;}
    }
    cout<<ans<<endl;
}
int32_t main(){
int t; cin>>t; while(t--)
solve();
return 0;
}


Comments

Submit
0 Comments
More Questions

96A - Football
702B - Powers of Two
1036A - Function Height
443A - Anton and Letters
1478B - Nezzar and Lucky Number
228A - Is your horseshoe on the other hoof
122A - Lucky Division
1611C - Polycarp Recovers the Permutation
432A - Choosing Teams
758A - Holiday Of Equality
1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram